package 剑指Offer._0110;

/**
 * @author yzh
 * @data 2021/3/26 22:59
 * 替换空格
 * 算法：字符串
 */
public class _05 {

    public String replaceSpace(String s) {
        // return s.replaceAll(" ", "%20");
        StringBuilder ans = new StringBuilder();
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if (chars[i] == ' ') ans.append("%20");
            else ans.append(chars[i]);
        }
        return ans.toString();
    }
}
